package com.meme.editor.gui.sprite2d;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;

import com.meme.app.AppRegistry;
import com.meme.editor.EntityObject;
import com.meme.editor.gui.EntityChildrenListView;
import com.meme.editor.gui.PropertyEditPanel;
import com.meme.editor.model.sprite2d.ModuleGroup;
import com.meme.editor.model.sprite2d.PureModuleGroup;
import com.meme.editor.model.sprite2d.Sprite2dFile;
import com.meme.editor.model.sprite2d.Tiled2dPalette;
import com.meme.editor.model.sprite2d.Tiled2dBackground;
import com.meme.editor.model.sprite2d.Sprite2dFile.TilePaletteSet;

import org.apache.log4j.Logger;

public class Tiled2dBackgroundContentPanel extends JPanel
{
	static Logger logger = Logger.getLogger (Tiled2dBackgroundContentPanel.class);
	

	JSplitPane mSplitPane_View;
	JSplitPane mSplitPane_Main;
	JSplitPane mSplitPane_Bottom;
	JSplitPane mSplitPane_Side;
	JTabbedPane mTabbedPanel;
	
	
	public Tiled2dBackgroundContentPanel (Tiled2dBackground tiled2dBackground)
	{
		int width  = ( (Integer) AppRegistry.getRegistry("editor.sprite2d.contentPanel.width") ).intValue();
		int height = ( (Integer) AppRegistry.getRegistry("editor.sprite2d.contentPanel.height") ).intValue();

		mTabbedPanel = new JTabbedPane ();
		//mTabbedPanel.setTabPlacement(JTabbedPane.BOTTOM);
		TilePaletteSet tilePaletteSet = (TilePaletteSet) ( ( (Sprite2dFile) ( tiled2dBackground.getHost() ) ).getTilePaletteSet() );	
		for (EntityObject group : tilePaletteSet.getChildren())
		{
			Tiled2dPalette tiled2dPalette = (Tiled2dPalette)group;			
			mTabbedPanel.add(tiled2dPalette.toString(), new Tiled2dPaletteView ( tiled2dPalette ) );
		}

		
		Tiled2dBackgroundView tiled2dBackgroundView = new Tiled2dBackgroundView (tiled2dBackground);
		tiled2dBackgroundView.setMinimumSize(new Dimension (320, 320));
	
		EntityChildrenListView layersListView = new EntityChildrenListView (tiled2dBackground);
		PropertyEditPanel layerPropertyPanel = new PropertyEditPanel ();
		layersListView.setPropertyEditPanel (layerPropertyPanel);
		
		//layersListView.getListComponent().addListSelectionListener (tiled2dBackgroundView);
		layersListView.getListComponent().addMouseListener(tiled2dBackgroundView);
		
		layersListView.getListComponent().setCellRenderer (new Tiled2dLayerListCellRenderer ());

		mSplitPane_Side = new JSplitPane (JSplitPane.VERTICAL_SPLIT, 
				layerPropertyPanel, 
				layersListView 
                );
		mSplitPane_Side.setResizeWeight (0.0);
		mSplitPane_Side.setDividerSize  (2);
		mSplitPane_Side.setDividerLocation (height / 4);
		
		mSplitPane_View = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, 
				mSplitPane_Side, 
				tiled2dBackgroundView 
                );
		mSplitPane_View.setResizeWeight (0.0);
		mSplitPane_View.setDividerSize  (2);
		mSplitPane_View.setDividerLocation (width / 4);
		
		mSplitPane_Main = new JSplitPane (JSplitPane.VERTICAL_SPLIT, 
				mSplitPane_View, 
				mTabbedPanel 
                );
		mSplitPane_Main.setResizeWeight (1.0);
		mSplitPane_Main.setDividerSize  (2);
		mSplitPane_Main.setDividerLocation (height * 2 / 3);
		
		setLayout ( new BorderLayout() );
		add (mSplitPane_Main, BorderLayout.CENTER);		

	}
}
